package serverSelction;

import java.util.ArrayList;

import java.util.List;

public class InitiateServerSelection {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		int k = 118;
		int n = k + 40;
	
		for (int z = 200; z < 500; z++) {
			n=(int) Math.ceil((double)n/.9);
			System.out.println("N value:"+n);
			GenerateServerAvailability g = new GenerateServerAvailability(k, n);
			int serverAvailability[] = g.serverAvailability();
			Helper h = new Helper(k, n);
			int[] serversWithDataRate = h.dataRateOfServers(serverAvailability);
			List<Integer> serversWithDataRateAL = new ArrayList<Integer>();
			for (int s : serversWithDataRate) {
				serversWithDataRateAL.add(s);
				// System.out.print(" "+s);
			}
			System.out.println(serversWithDataRateAL.size() + " " + k + " ");
			int[] servers = new int[k];
			List<Integer> srvr = new ArrayList<Integer>();
			for (int i = 0; i < k; i++) {
				servers[i] = serversWithDataRateAL.get(i);
				srvr.add(serversWithDataRate[i]);
			}
			// for ( int i: serversWithDataRate){
			// // System.out.println("Acceptable data rate"+i);
			// }
			int[] serverIndex = h.onTheFlyServer(servers);

			List<Integer> srvrIndx = new ArrayList<Integer>();

			for (int i : serverIndex) {
				srvrIndx.add(i);
			}
			System.out.println(serverIndex.length +":"+ k);

			while (serverIndex.length < k) {
				// for ( int s : srvrIndx){
				// System.out.print(" "+s);
				// }
				System.out.println("Server index len:"+serverIndex.length);
				if(!srvr.removeAll(srvrIndx))
					System.out.println("ERROR!!!!!");
				// System.out.println(" \nafter removing elements");
				// for ( int s : srvr){
				// System.out.print(" "+s);
				// }

				serversWithDataRateAL.removeAll(srvr);
				System.out.println(" SIZE:" + serversWithDataRateAL.size() );
				System.out.println(" K val: " + k);
			    System.out.println(" array val: " + serversWithDataRateAL.get(k) + " $$$");
//				System.out.println(serversWithDataRateAL.get(k + 1) + " "
//						+ serversWithDataRateAL.size());
			    servers = new int[k];
				for (int i = 0; i <= k - 1; i++) {
					//System.out.println(i);
					servers[i] = serversWithDataRateAL.get(i);
					srvr.add(serversWithDataRateAL.get(i));
					//System.out.println(i);
				}
				serverIndex = h.onTheFlyServer(servers);
				// for ( int s : serverIndex){
				// System.out.print(" "+s);
				// }
			}

			// else {
			System.out.println("\nResult of gaussian elimination"
					+ h.gaussianElimination(serverIndex) + " ");
			// System.out.println(" return the index of servers");
			// }
			// for( int i: serverIndex){
			// // System.out.println("from the On the fly"+i);
			// }
			// if(h.gaussianElimination(serverIndex)==0){
			//
			// }
			// System.out.println();
			// for ( int i:serverIndex)
			// System.out.print(" "+i);
			k = k + 1;
			n = k + 40;
		}
		//
	}

}
